<!-- start-->
<div class=" edit">

    <!-- 表单 -->   
    <section class="panel-body">
        <form role="form" class="form-edit">
            <input type="hidden" name="id" value="{:$row.id}">

            <div class="form-group col-sm-12">
                <span>客户类型</span>
                <select name="type" class="form-control" v-model="type">
                    <option value="0">个人</option>
                    <option value="1">商家</option>
                </select>
            </div>

            <div class="form-group col-sm-12" v-show="type">
                <span>公司名称</span>
                <input type="text" class="form-control" placeholder="公司名称" name="title" value="{$row.title}">
            </div>
            
            <div class="form-group col-sm-6" v-show="type">
                <span>社会信用代码</span>
                <input type="text" class="form-control" placeholder="社会信用代码" name="credit_id" value="{$row.credit_id}">
            </div>

            <div class="form-group col-sm-6" v-show="type">
                <span>纳税人识别号</span>
                <input type="text" class="form-control" placeholder="纳税人识别号" name="taxpayer_id" value="{$row.taxpayer_id}">
            </div>

            <div class="form-group col-sm-6" v-show="type">
                <span>开户银行</span>
                <select name="bank" class="form-control bank" v-model="current_bank">
                    <option :value="item" v-for="item in bank" v-text="item"></option>
                </select>
            </div>

            <div class="form-group col-sm-6" v-show="type">
                <span>开户卡号</span>
                <input type="text" class="form-control" placeholder="开户卡号" name="bank_number" value="{$row.bank_number}">
            </div>

            <div class="form-group col-sm-12" v-show="type">
                <span>开户行地址</span>
                <input type="text" class="form-control" placeholder="联系人" name="bank_address" value="{$row.bank_address}">
            </div>

            <div class="form-group col-sm-12">
                <span>联系人</span>
                <input type="text" class="form-control" placeholder="联系人" name="contact" value="{$row.contact}">
            </div>

            <div class="form-group col-sm-6" v-show="type">
                <span>电话</span>
                <input type="text" class="form-control" placeholder="电话" name="tel" value="{$row.tel}">
            </div>

            <div class="form-group col-sm-6" v-show="type">
                <span>传真</span>
                <input type="text" class="form-control" placeholder="传真" name="fax" value="{$row.fax}">
            </div>

            <div class="form-group col-sm-6">
                <span>手机</span>
                <input type="text" class="form-control" placeholder="手机" name="phone" value="{$row.phone}">
            </div>

            <div class="form-group col-sm-6">
                <span>邮箱</span>
                <input type="text" class="form-control" placeholder="邮箱" name="email" value="{$row.email}">
            </div>                

            <div class="form-group col-sm-12">
                <span>状态</span>
                <div class="radio">
                    <label><input type="radio" name="status" value="0" {$row->status== 0 ? 'checked="checked"' : null } >正常</label>
                </div>
                <div class="radio">
                    <label><input type="radio" name="status" value="1" {$row->status== 1 ? 'checked="checked"' : null } >禁用</label>
                </div>
            </div>

            <div class="form-group col-sm-12">
                <span>地区</span>
                <div data-toggle="distpicker" class="distpicker col-sm-12">
                    <select class="form-control col-sm-3" name="province" style="width:auto;"></select>
                    <select class="form-control col-sm-2" name="city" style="width:auto;"></select>
                    <select class="form-control col-sm-2" name="district" style="width:auto;"></select>
                </div>
            </div>

            <div class="form-group col-sm-12">
                <span>街道地址</span>
                <input type="text" class="form-control" placeholder="街道地址" name="street" value="{$row.street}">
            </div>


            <div class="form-group col-sm-12">
                <span>备注</span>
                <textarea class="form-control" cols="5" name="desc">{$row.desc}</textarea>
            </div>

        </form>

    </section>

    <div class="form-group col-sm-12 panel-footer bg-none">
        <button type="button" class="btn btn-sm btn btn-primary" @click="save">  保 存 </button>
        <button type="reset" class="btn btn-sm btn-success ">  重 置 </button> 
    </div>


</div>
<!-- end -->

<script>

seajs.use(['vendor/bank','js/distpicker.min','vendor/comboSelect/jquery.combo.select'], function() {
    var edit = new Vue({
        el: '.edit',
        data: {
            type: {$row.type},
            bank: bank_list,
            current_bank: "{$row.bank}"
        },
        mounted: function(){
            $(".distpicker").distpicker({
                province: '{$row.province}',
                city: '{$row.city}',
                district: '{$row.district}'
            });
            $('.bank').comboSelect();
        },
        methods:{
            save: function () {
                var param = $('.form-edit').serializeArray();
                $.ajax({
                    url: "{:url('update')}",
                    method: 'POST',
                    dataType: 'json',
                    data: param,
                    success: this.callback
                });
            },
            callback:function (data) {
                if( data.error >0 ){
                    toastr.error(data.msg);
                }else{
                    toastr.success(data.msg);
                    Table.methods.refresh();
                    layer.closeAll('page');
                }
            }
        },
        watch:{
            type:function(newVal,oldVal){
                this.type = (newVal == '1') ? 1 : 0;
            }
        }
    });

});
</script>